package com.zjn.servicea.controller;


import com.alibaba.fastjson.JSONArray;
import com.zjn.entity.User;
import com.zjn.entity.UserInfoAll;
import com.zjn.entity.UserInfoReq;
import com.zjn.servicea.service.UserService;
import com.zjn.servicea.service.feign.ServiceAFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.function.EntityResponse;

import java.util.List;

/**
 * @author zaker
 * @program: signit_parent
 * @date 2021-03-30 13:39
 */
@RestController
public class UserController implements ServiceAFeign {

    @Autowired
    private UserService userService;

    @PostMapping("/updateuser")
    public String UpdateUserInfo(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @GetMapping("/getInfoAll")
    public @ResponseBody String getInfoAll(@RequestBody UserInfoReq userInfoReq,
                      @RequestParam(name = "offset", required = false, defaultValue = "0") Integer offset,
                      @RequestParam(name = "limit", required = false, defaultValue = "20") Integer limit){

            List<UserInfoReq> userInfoAlls= userService.getUicInfo(userInfoReq.getId(),
                    userInfoReq.getIdNo(),offset,limit);

            return JSONArray.toJSONString(userInfoAlls);
    }

    @Override
    @PostMapping("/createUser")
    public String createUser(UserInfoReq userInfoReq) {

        return userService.createUserAll(userInfoReq);
    }
}
